package cn.dt70.service.impl;

import cn.dt70.dao.aqbGrowth.AqbGrowthMapper;
import cn.dt70.pojo.AqbGrowth;
import cn.dt70.service.AqbGrowthService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class AqbGrowthServiceImpl implements AqbGrowthService {

    private static final Logger LOGGER = Logger.getLogger(AqbGrowthServiceImpl.class);

    @Resource
    private AqbGrowthMapper aqbGrowthMapper;

    //根据用户id查询成长值
    @Override
    public AqbGrowth getGrowthByUserCode(String userCode) {
        AqbGrowth growthList = new AqbGrowth();
        try {
            growthList = aqbGrowthMapper.getGrowthById(userCode);
            if (null == growthList){
                LOGGER.debug("AqbGrowthServiceImpl.getGrowthById 为空");
            }else {
                LOGGER.debug("AqbGrowthServiceImpl.getGrowthById 成功");
            }
        } catch (Exception e) {
            LOGGER.error("AqbGrowthServiceImpl.getGrowthById 异常："+e.getMessage());
        }
        return growthList;
    }

    //增加成长值
    @Override
    public boolean addGrowth(AqbGrowth growth) {
        boolean result = false;
        try {
            int i = aqbGrowthMapper.addGrowth(growth);
            if (i == 0){
                LOGGER.debug("AqbGrowthServiceImpl.addGrowth 为空");
            }else {
                LOGGER.debug("AqbGrowthServiceImpl.addGrowth 成功");
                result = true;
            }
        } catch (Exception e) {
            LOGGER.error("AqbGrowthServiceImpl.addGrowth 异常："+e.getMessage());
        }
        return result;
    }

    //添加用户名
    @Override
    public boolean addUserCode(String userCode) {
        boolean flag=false;
        int row=0;
        try {
            row =aqbGrowthMapper.saveUserCode(userCode);
            if(row !=1){
                LOGGER.debug("aqbGrowthMapper.saveUserCode 添加用户名失败");
            }else{
                LOGGER.debug("aqbGrowthMapper.saveUserCode 添加用户名成功");
                return true;
            }
        } catch (Exception e) {
            LOGGER.debug("aqbGrowthMapper.saveUserCode 添加用户名异常"+e.getMessage());
        }
        return flag;
    }

    //根据用户名修改成长值
    @Override
    public boolean updGrowthByUserCode(String userCode, int integral) {
        boolean flag=false;
        try {
            int i = aqbGrowthMapper.updGrowthByUserCode(userCode, integral);

            if (i== 0){
                LOGGER.debug("aqbGrowthMapper.updGrowthByUserCode 成长值增加失败");
            }else {
                LOGGER.debug("aqbGrowthMapper.updGrowthByUserCode 成长值增加成功");
                flag = true;
            }
        } catch (Exception e) {
            LOGGER.debug("aqbGrowthMapper.saveUserCode 成长值增加异常"+e.getMessage());
        }
        return flag;
    }
}


